﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IGGCore;
using System.Globalization;

namespace IGGConsole
{
    public class ModeTransactionsFormatter : IModeFormatter
    {
        #region IModeFormatter Members

        private int m_max = 28;

        public void FormatMode(Scoreboard board, int max)
        {
            m_max = max;
            FormatMode(board);
            m_max = 28;
        }

        /// <summary>
        /// Format the history tidbit
        /// </summary>
        public void FormatMode(Scoreboard board)
        {
            CultureInfo culture = new CultureInfo("en-ca");
            if (m_max > 20)
            {
                Console.WriteLine();
                Console.WriteLine(" Transactions");
            }
            Console.WriteLine();

            int count = 1;
            while (count < m_max)
            {
                foreach (TransactionDay day in board.Transactions)
                {
                    Console.WriteLine(" " + day.Date.ToString("MMMM d, yyyy", culture).ToUpper());
                    foreach (Transaction trans in day.Transactions)
                    {
                        Console.Write(" " + ToolBox.GetFormattedStringPadRight(trans.Team, 23));
                        Console.Write(" " + ToolBox.GetFormattedStringPadRight(trans.Player, 20));
                        Console.Write(" " + ToolBox.GetFormattedStringPadRight(trans.ActionAbbr, 33));
                        Console.WriteLine();
                        count++;
                        if (count == m_max)
                        {
                            break;
                        }
                    }
                    Console.WriteLine();
                    if (count == m_max)
                    {
                        break;
                    }
                }
            }
        }

        #endregion
    }
}
